package lucene.server.database.meta;

import lucene.server.database.model.ColumnModel;
import lucene.server.database.model.DatabaseModel;
import lucene.server.database.model.TableModel;
import lucene.server.database.utils.DatabaseUtil;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

public class OracleDialect extends AbstractDialect{
    public OracleDialect(String databaseType) {
        super(databaseType);
    }

    @Override
    public Map<String,DatabaseModel> getDataBases(Connection connection) {
        Map<String,DatabaseModel> databaseModels = new HashMap<>();
        ResultSet schemas = null;
        try {
            schemas = connection.getMetaData().getSchemas();
            while (schemas.next()) {
                DatabaseModel databaseModel = new DatabaseModel();
                databaseModel.setCatalog("");
                databaseModel.setName(schemas.getString("TABLE_SCHEM"));
                databaseModel.setSchema(schemas.getString("TABLE_SCHEM"));
                databaseModels.put(databaseModel.getName(),databaseModel);
                databaseModel.setType(databaseType);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            DatabaseUtil.close(connection,schemas);
        }
        return databaseModels;
    }
    @Override
    public void setColumns(Connection connection, DatabaseModel databaseModel, TableModel tableModel) {
         super.setColumns(connection,databaseModel,tableModel);

    }


}
